<template>
  <div>
    <a-table :columns="columns" :data="datas">
      <template #agree="{ record }">
        <a-button @click="agreeSubmit(record.supId)">同意</a-button>
      </template>
      <template #reject="{ record }">
        <a-button @click="rejectSubmit(record.supId)">驳回</a-button>
      </template>
    </a-table>
  </div>
</template>
    
  <script>
import { reactive } from "vue";
import axios from "axios";
import store from "@/store";

export default {
  data() {
    const columns = [
      {
        title: "ID",
        dataIndex: "supId",
      },
      {
        title: "申请人",
        dataIndex: "supName",
      },
      {
        title: "申请码",
        dataIndex: "supCode",
      },
      {
        title: "申请身份",
        dataIndex: "supIdentity",
      },
      {
        title: "处理情况",
        dataIndex: "supHandle",
      },
      {
        title: "同意",
        slotName: "agree",
      },
      {
        title: "驳回",
        slotName: "reject",
      },
    ];
    return {
      handle: "YES",
      datas: [
        {
          // key: "1",
          supId: 1,
          supName: "cac",
          supCode: "8888",
          supIdentity: "teacher",
          supHandle: "未处理",
        },
        {
          // key: "1",
          supId: 1,
          supName: "cac",
          supCode: "8888",
          supIdentity: "teacher",
          supHandle: "未处理",
        },
      ],
      columns,
    };
  },
  methods: {
    agreeSubmit(key) {
      (this.handle = "YES"), 
      this.handelRole(key);
      setTimeout(()=>{
        this.searchInfo();
      },1000);
    },

    rejectSubmit(key) {
      (this.handle = "NO"), 
      this.handelRole(key);
      setTimeout(()=>{
        this.searchInfo();
      },1000);
    },

    handelRole(id) {
      axios
        .post("/submit/handleRoleSubmit", {
          userID: id,
          isHandle: this.handle,
        })
        .then((response) => {
          if (response.data) {
            alert("操作成功");
          } else {
            alert("操作失败");
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    },

    searchInfo() {
      axios.get("/submit/search").then((response) => {
        this.datas = response.data;
      });
    },
  },

  created() {
    axios
      .get("/submit/search")
      .then((response) => {
        this.datas = response.data;
      })
      .catch(function (error) {
        console.log(error);
      });
  },
};
</script>
    